package com.zglc.ms;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.google.common.collect.Lists;
import com.zglc.ms.shop.filter.AllowOriginInterceptor;
import com.zglc.ms.shop.filter.JwtFilter;

@SpringBootApplication
@EnableScheduling
public class App extends WebMvcConfigurerAdapter {

	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}

	/*@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new AllowOriginInterceptor()).addPathPatterns("/front/**");
		super.addInterceptors(registry);
	}*/

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/front/*").allowedOrigins("*");
	}

	@Bean
	FilterRegistrationBean jwtFilter() {
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		registrationBean.setFilter(new JwtFilter());
		List<String> urlList = Lists.newArrayList();
		urlList.add("/front/*");
		registrationBean.setUrlPatterns(urlList);
		return registrationBean;
	}

}